// app.js
App({
  onLaunch() {
    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
      }
    })
  },
  globalData: {
    userInfo: null,
    // 题库分类数据
    questionBanks: [
      {
        id: 1,
        name: "前端开发基础",
        description: "HTML、CSS、JavaScript基础知识",
        detailDescription: "本题库涵盖前端开发的核心技术栈，包括HTML语义化标签、CSS布局技巧、JavaScript基础语法、DOM操作、事件处理等内容。适合前端开发初学者和需要巩固基础的开发者。",
        questionCount: 25,
        difficulty: "简单",
        tags: ["HTML", "CSS", "JavaScript"],
        questionIds: [1, 2, 3, 4, 5]
      },
      {
        id: 2,
        name: "React框架进阶",
        description: "React组件、状态管理、生命周期",
        detailDescription: "深入学习React框架的高级特性，包括组件设计模式、状态管理方案、性能优化技巧、Hook使用、Context API等。帮助开发者掌握现代React开发的最佳实践。",
        questionCount: 30,
        difficulty: "中等",
        tags: ["React", "Hook", "状态管理"],
        questionIds: [6, 7, 8]
      },
      {
        id: 3,
        name: "算法与数据结构",
        description: "常见算法题目和数据结构应用",
        detailDescription: "系统性学习计算机科学中的核心算法和数据结构，包括排序算法、搜索算法、动态规划、树和图的遍历、哈希表等。提升编程思维和解决复杂问题的能力。",
        questionCount: 40,
        difficulty: "困难",
        tags: ["算法", "数据结构", "编程"],
        questionIds: [9, 10]
      },
      {
        id: 4,
        name: "Node.js后端开发",
        description: "服务端JavaScript开发技术",
        detailDescription: "全面掌握Node.js后端开发技术，包括Express框架使用、数据库操作、API设计、中间件开发、错误处理、性能优化等。构建高效可靠的后端服务。",
        questionCount: 35,
        difficulty: "中等",
        tags: ["Node.js", "Express", "API"],
        questionIds: [11, 12]
      }
    ],
    // 题目数据 - 支持多种题型
    questionBank: [
      {
        id: 1,
        title: "JavaScript中var、let、const的区别是什么？",
        type: "single",
        difficulty: "medium",
        options: [
          { label: "A", text: "var有块级作用域，let和const没有" },
          { label: "B", text: "let和const有块级作用域，var没有" },
          { label: "C", text: "三者都有块级作用域" },
          { label: "D", text: "三者都没有块级作用域" }
        ],
        correctAnswer: 1,
        analysis: "let和const是ES6引入的新特性，具有块级作用域，而var只有函数作用域。let可以重新赋值，const声明的变量不能重新赋值。"
      },
      {
        id: 2,
        title: "以下哪些是JavaScript的基本数据类型？",
        type: "multiple",
        difficulty: "easy",
        options: [
          { label: "A", text: "string" },
          { label: "B", text: "number" },
          { label: "C", text: "object" },
          { label: "D", text: "boolean" }
        ],
        correctAnswer: [0, 1, 3],
        analysis: "JavaScript的基本数据类型包括：string、number、boolean、null、undefined、symbol、bigint。object是引用数据类型，不是基本数据类型。"
      },
      {
        id: 3,
        title: "请写出JavaScript中数组去重的一种方法",
        type: "fill",
        difficulty: "medium",
        correctAnswer: "[...new Set(array)]",
        analysis: "使用ES6的Set数据结构可以轻松实现数组去重。Set只存储唯一值，结合扩展运算符可以将Set转换回数组。"
      },
      {
        id: 4,
        title: "JavaScript是一种编译型语言",
        type: "judge",
        difficulty: "easy",
        correctAnswer: false,
        analysis: "JavaScript是一种解释型语言，代码在运行时由JavaScript引擎逐行解释执行，而不是预先编译成机器码。"
      },
      {
        id: 5,
        title: "CSS中position属性的默认值是什么？",
        type: "single",
        difficulty: "easy",
        options: [
          { label: "A", text: "relative" },
          { label: "B", text: "absolute" },
          { label: "C", text: "static" },
          { label: "D", text: "fixed" }
        ],
        correctAnswer: 2,
        analysis: "position属性的默认值是static，表示元素按照正常的文档流进行布局，不受top、right、bottom、left属性影响。"
      },
      {
        id: 6,
        title: "React中useState Hook的正确使用方式是？",
        type: "single",
        difficulty: "medium",
        options: [
          { label: "A", text: "const [state, setState] = useState(initialValue)" },
          { label: "B", text: "const state = useState(initialValue)" },
          { label: "C", text: "const setState = useState(initialValue)" },
          { label: "D", text: "useState(initialValue)" }
        ],
        correctAnswer: 0,
        analysis: "useState Hook返回一个数组，第一个元素是当前状态值，第二个元素是更新状态的函数。使用数组解构赋值来获取这两个值。"
      },
      {
        id: 7,
        title: "以下哪些是React Hook的规则？",
        type: "multiple",
        difficulty: "medium",
        options: [
          { label: "A", text: "只能在函数组件中使用" },
          { label: "B", text: "只能在组件顶层调用" },
          { label: "C", text: "可以在循环中调用" },
          { label: "D", text: "不能在条件语句中调用" }
        ],
        correctAnswer: [0, 1, 3],
        analysis: "React Hook的使用规则：1. 只能在函数组件或自定义Hook中使用；2. 只能在组件的顶层调用，不能在循环、条件或嵌套函数中调用。"
      },
      {
        id: 8,
        title: "请写出创建React函数组件的基本语法",
        type: "fill",
        difficulty: "easy",
        correctAnswer: "function Component() { return <div></div>; }",
        analysis: "React函数组件是一个返回JSX的JavaScript函数。可以使用function声明或箭头函数的方式创建。"
      },
      {
        id: 9,
        title: "时间复杂度O(n²)表示算法效率很高",
        type: "judge",
        difficulty: "medium",
        correctAnswer: false,
        analysis: "O(n²)表示二次时间复杂度，随着输入规模增长，执行时间呈平方级增长，效率相对较低。O(1)、O(log n)、O(n)的效率更高。"
      },
      {
        id: 10,
        title: "以下哪些是常见的排序算法？",
        type: "multiple",
        difficulty: "medium",
        options: [
          { label: "A", text: "冒泡排序" },
          { label: "B", text: "快速排序" },
          { label: "C", text: "深度优先搜索" },
          { label: "D", text: "归并排序" }
        ],
        correctAnswer: [0, 1, 3],
        analysis: "冒泡排序、快速排序、归并排序都是经典的排序算法。深度优先搜索(DFS)是图遍历算法，不是排序算法。"
      },
      {
        id: 11,
        title: "Node.js是基于哪个JavaScript引擎构建的？",
        type: "single",
        difficulty: "easy",
        options: [
          { label: "A", text: "SpiderMonkey" },
          { label: "B", text: "V8" },
          { label: "C", text: "Chakra" },
          { label: "D", text: "JavaScriptCore" }
        ],
        correctAnswer: 1,
        analysis: "Node.js是基于Google Chrome的V8 JavaScript引擎构建的，V8引擎以其高性能和快速执行而闻名。"
      },
      {
        id: 12,
        title: "Express.js是一个同步框架",
        type: "judge",
        difficulty: "easy",
        correctAnswer: false,
        analysis: "Express.js是一个异步的Node.js Web框架，支持异步操作和中间件，能够处理并发请求而不阻塞。"
      }
    ],
    favorites: [],
    history: []
  }
})